package com.isunland.managesystem.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.LinearLayout;
import android.widget.TextView;
import com.isunland.managesystem.R;
import com.isunland.managesystem.entity.ShouldGathPayList.GatheringDetail;
import java.util.List;

public class ShouldPayListAdapter extends ArrayAdapter<GatheringDetail> {

  /**
   * ViewHolder class for layout.<br />
   * <br />
   * Auto-created on 2016-03-02 14:00:26 by Android Layout Finder
   * (http://www.buzzingandroid.com/tools/android-layout-finder)
   */
  private static class ViewHolder {
    public final LinearLayout rootView;
    public final TextView tvUnitCon;
    public final TextView tvUnitShould;
    public final TextView tvNameCon;
    public final TextView tvNameShould;
    public final TextView tvMoneyCon;
    public final TextView tvMoneyShould;

    private ViewHolder(LinearLayout rootView, TextView tvUnitCon, TextView tvUnitShould,
        TextView tvNameCon, TextView tvNameShould, TextView tvMoneyCon, TextView tvMoneyShould) {
      this.rootView = rootView;
      this.tvUnitShould = tvUnitShould;
      this.tvNameShould = tvNameShould;
      this.tvMoneyShould = tvMoneyShould;
      this.tvUnitCon = tvUnitCon;
      this.tvNameCon = tvNameCon;
      this.tvMoneyCon = tvMoneyCon;
    }

    public static ViewHolder create(LinearLayout rootView) {
      TextView tvUnitShould = (TextView) rootView.findViewById(R.id.tv_unit_should);
      TextView tvNameShould = (TextView) rootView.findViewById(R.id.tv_name_should);
      TextView tvMoneyShould = (TextView) rootView.findViewById(R.id.tv_money_should);
      TextView tvUnitCon = (TextView) rootView.findViewById(R.id.tv_unitCon);
      TextView tvNameCon = (TextView) rootView.findViewById(R.id.tv_nameCon);
      TextView tvMoneyCon = (TextView) rootView.findViewById(R.id.tv_moneyCon);
      return new ViewHolder(rootView, tvUnitCon, tvUnitShould, tvNameCon, tvNameShould, tvMoneyCon,
          tvMoneyShould);
    }
  }

  @Override public View getView(int position, View convertView, ViewGroup parent) {
    final ViewHolder vh;
    if (convertView == null) {
      View view = mInflater.inflate(R.layout.adapter_gather_pay, parent, false);
      vh = ViewHolder.create((LinearLayout) view);
      view.setTag(vh);
    } else {
      vh = (ViewHolder) convertView.getTag();
    }

    GatheringDetail item = getItem(position);
    vh.tvUnitCon.setText(getContext().getString(R.string.communicateUnit));
    vh.tvUnitShould.setText(item.getPartName());
    vh.tvNameCon.setText(getContext().getString(R.string.contractDeliveryName));
    vh.tvNameShould.setText(item.getContractName());
    vh.tvMoneyCon.setText(getContext().getString(R.string.notCulculateMoney));
    vh.tvMoneyShould.setText(item.getContractAmount());

    return vh.rootView;
  }

  private LayoutInflater mInflater;

  public ShouldPayListAdapter(Context context, List<GatheringDetail> objects) {
    super(context, 0, objects);
    this.mInflater = LayoutInflater.from(context);
  }

  public ShouldPayListAdapter(Context context, GatheringDetail[] objects) {
    super(context, 0, objects);
    this.mInflater = LayoutInflater.from(context);
  }
}
